﻿using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UIDocumentTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetHorizontalScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument("@AutomationId='documentViewer1'");
            Assert.AreEqual(ScrollPattern.NoScroll, document.HorizontalScrollPercent);
        }

        [TestMethod]
        public void ShouldGetHorizontalViewSize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument("@AutomationId='documentViewer1'");
            Assert.AreEqual(100.0, document.HorizontalViewSize);
        }

        [TestMethod]
        public void ShouldGetHorizontallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument(); 
            Assert.IsFalse(document.HorizontallyScrollable);
        }

        [TestMethod]
        public void ShouldGetVerticalScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument("@AutomationId='documentViewer1'");
            Assert.AreEqual(ScrollPattern.NoScroll, document.VerticalScrollPercent);
        }

        [TestMethod]
        public void ShouldGetVerticalViewSize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument("@AutomationId='documentViewer1'");
            Assert.AreEqual(100.0, document.VerticalViewSize);
        }

        [TestMethod]
        public void ShouldGetVerticallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument();
            Assert.IsFalse(document.VerticallyScrollable);
        }

        [TestMethod]
        public void ShouldGetValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument();
            Assert.AreEqual(null, document.Value);
        }

        [TestMethod]
        public void ShouldGetDocumentRange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument();
            Assert.AreEqual(null, document.DocumentRange);
        }

        [TestMethod]
        public void ShouldGetSupportedTextSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIDocument document = tabItem2.UIDocument();
            Assert.AreEqual(SupportedTextSelection.None, document.SupportedTextSelection);
        }

        [TestMethod]
        public void ShouldGetAllDocuments()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            List<UIDocument> documents = window.UIDocuments();
            Assert.AreEqual(1, documents.Count);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}